package com.systemsjr.jrbbf.expense;

import java.util.Vector;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
import net.rim.device.api.ui.component.Menu;

import com.systemsjr.jrbbf.common.ExpenseManagerScreen;

public class ExpenseTypeList extends ExpenseManagerScreen{
	private Vector expenseTypes;
	private ListField listField;
	
	public ExpenseTypeList(ManageExpenseType sqlManager2){
        setTitle("Expense Types");
        sqlManager = sqlManager2;
        expenseTypes = ((ManageExpenseType)sqlManager).getAll();
        listField = new ListField();
        ListCallback _callback = new ListCallback();
        
        listField.setCallback(_callback);
        add(listField);
        listField.setSize(expenseTypes.size());
        
	}
	
	protected void makeMenu(Menu menu, int instance)
    {		
		menu.add(exipApp());
		menu.add(addExpenseType());
    }
	
	private class ListCallback implements ListFieldCallback
	{
	    public void drawListRow(ListField list, Graphics g, int index, int y, int w) 
	    { 
	        ExpenseType text = (ExpenseType)expenseTypes.elementAt(index); 
	        g.drawText(text.getCode(), 0, y, 0, w); 
	    } 
	    public Object get(ListField list, int index) 
	    {
	        return expenseTypes.elementAt(index); 
	    } 
	    public int indexOfList(ListField list, String prefix, int string) 
	    { 
	        return expenseTypes.indexOf(prefix, string); 
	    } 
	    public int getPreferredWidth(ListField list) 
	    { 
	        return Display.getWidth(); 
	    } 
	}

	protected void doReload() {
		// TODO Auto-generated method stub
		
	}	
}


